package gui.reportsTab;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * class OutlookFindThread
 * finds the oulook's path on the computer where the program is intalled.
 * @author michal
 *
 */
public class OutlookFindThread extends Thread {
	static String outlook;	//holds the outlook's path
	boolean closed = false;	//indicates if the thread has finished.
	Process findOutlookProcess=null;	//process that finds the outlook's path
	/**
	 * outlook getter
	 * @return
	 */
	public String getOutlook(){
		return outlook;
	}
	
	/**
	 * starts a new process which finds the outlook's path
	 */
	public void run(){
		try {
			//calling the WHERE command
			findOutlookProcess = new ProcessBuilder("WHERE","/R","c:\\","outlook.exe").start();
			BufferedReader input= new BufferedReader(new InputStreamReader(findOutlookProcess.getInputStream()));
			//reading the first answer  
			outlook=input.readLine();	
			//finished
			findOutlookProcess.destroy();
			closed = true;
		} catch (IOException e3) {
			e3.printStackTrace();
		}
	}
	
	/**
	 * closes the thread
	 */
	public void closeThread(){
		if (findOutlookProcess!=null){
			findOutlookProcess.destroy();
		}
	}
}
